package xgd

import (
	"net/http"

	"xlib/log"

	D "TCP/define"

	"github.com/gin-gonic/gin"
)

//http://127.0.0.1:7778/xgd?action=get_current_time
//Get GET请求
func Get(c *gin.Context) {
	action := c.Query(D.Action)

	switch action {
	//case getDoors:
	//	GetDoorsHandler(c)
	//case getDoorState:
	//	GetDoorStateHandler(c)
	//case getTimeGroup:
	//	GetTimeGroupHandler(c)
	//case getCards:
	//	GetCardsHandler(c)
	//case getCard:
	//	GetCardHandler(c)
	//case getEvent:
	//    GetEventHandler(c)
	//case getHistoryEvent:
	//    GetHistoryEventHandler(c)
	// 这里access*接口本来是单独给kehua做的，现在腾讯协议中有相同的要求，以后统一调用一个handler
	//case getEvent, getAccessEvent:
	//	GetEventHandler(c)
	//case getHistoryEvent, getAccessHistoryEvent:
	//	GetHistoryEventHandler(c)
	case getCurrentTime:
		GetCurrentTimeHandler(c)
	case getLog:
		GetLogHandler(c)
	case delLog:
		DelLogHandler(c)
	case getAPNByPara:
		//http://eleuu.com:7778/xgd?action=get_apn_by_para&mcc=460&mnc=00
		GetAPNByPara(c)
	case getDrvInfo:
		//http://eleuu.com:7778/xgd?action=get_drv_info&sn=KD5831B9957
		GetDrvInfoHandler(c)
	case getLogInfo:

		GetLogInfoHandler(c)
	case "":
		log.Error(`"action" is nil`)
		D.ErrorCodeWithExtraInfo(c, http.StatusOK, D.EcParamMissing, D.EmParamMissing, `"action" is nil`)
	default:
		log.Errorf(`no such action named "%s"`, action)
		D.ErrorCodeWithExtraInfo(c, http.StatusOK, D.EcUnsupportedAction, D.EmUnsupportedAction, "no such action named "+action)
	}
}

//Post POST请求
func Post(c *gin.Context) {
	action := c.Query(D.Action)

	switch action {
	//case setDoorState:
	//	SetDoorStateHandler(c)
	//case setTimeGroup:
	//	SetTimeGroupHandler(c)
	//case clearTimeGroup:
	//	ClearTimeGroupHandler(c)
	//case addCard:
	//	AddCardHandler(c)
	//case modifyCard:
	//	SetCardHandler(c)
	//case deleteCard:
	//	DeleteCardHandler(c)
	//case cleanDevice:
	//	CleanDeviceHandler(c)
	case setCurrentTime:
		SetCurrentTimeHandler(c)
	case "":
		log.Error(`"action" is nil`)
		D.ErrorCodeWithExtraInfo(c, http.StatusOK, D.EcParamMissing, D.EmParamMissing, "'action' is nil")
	default:
		log.Errorf(`no such action named "%s"`, action)
		D.ErrorCodeWithExtraInfo(c, http.StatusOK, D.EcUnsupportedAction, D.EmUnsupportedAction, "no such action named "+action)
	}
}
func ShowLogInfo(c *gin.Context) {
	c.HTML(http.StatusOK, "show.html", gin.H{})
}
func ShowDrvInfo(c *gin.Context) {
	c.HTML(http.StatusOK, "info.html", gin.H{})
}
